﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ScreenMonitor.WcfServerUITest
{
    public partial class Form1 : Form
    {
        ServiceHost host = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                host = new ServiceHost(typeof(ScreenMonitor.ServerWcfService.ServerMainServuce));
                host.Open();
                MessageBox.Show("服务启动成功！");
                button1.Enabled = false;
                button2.Enabled=true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("服务启动失败：" + ex.Message);
                button1.Enabled = true;
                button2.Enabled = false;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                host.Close();
                MessageBox.Show("服务关闭成功！");
                button1.Enabled = true;
                button2.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("服务关闭失败：" + ex.Message);
                button1.Enabled = false;
                button2.Enabled = true;
            }
        }
    }
}
